package dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class BaseDao<T> {

	QueryRunner  queryRunner=new QueryRunner();
	
	public void update(Connection connection,String sql,Object...args) throws SQLException {
		queryRunner.update(connection, sql, args);
	}
	
	
	public T get(Connection connection,String sql,Class<T> clazz,Object...args) throws SQLException {
		
		ResultSetHandler<T> rsh = new BeanHandler<T>(clazz);
		 T t = queryRunner.query(connection, sql, rsh, args);
		 return t;
	}
	
	public List<T> getList(Connection connection,String sql,Class<T> clazz,Object...args) throws SQLException{
		
		ResultSetHandler<List<T>> rsh = new BeanListHandler<T>(clazz);
		 List<T> list = queryRunner.query(connection, sql, rsh, args);
		return list;
	}
	
	
	
}
